//
//  DYBaseFormView.m
//  TerritoryShopkeeper
//
//  Created by 黄德玉 on 2018/7/12.
//  Copyright © 2018年 ZDQK. All rights reserved.
//

#import "DYBaseFormView.h"
#import <Masonry/Masonry.h>

@interface DYBaseInputUnitView()<UITextFieldDelegate>
@property (nonatomic,strong) UIView * btmLine;
@end

@implementation DYBaseInputUnitView

- (instancetype)init{
    if (self = [super init]) {
        self.titleLabel = [UILabel new];
        self.titleLabel.font = [UIFont systemFontOfSize:14];
        self.titleLabel.textColor = [UIColor grayTextColor];
        [self.titleLabel setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
        self.titleLabel.textAlignment = NSTextAlignmentCenter;
        self.titleLabel.numberOfLines = 1;
        [self addSubview:self.titleLabel];
        
        self.textfield = [[UITextField alloc] init];
        self.textfield.font = [UIFont systemFontOfSize:14];
        self.textfield.delegate = self;
        self.textfield.textAlignment = NSTextAlignmentRight;
        [self addSubview:self.textfield];
        
        self.btmLine = [UIView new];
        self.btmLine.backgroundColor = [[UIColor lightGrayColor] colorWithAlphaComponent:.5];
        [self addSubview:self.btmLine];
        [self _layout];
        
    }
    return self;
}

- (void)_layout{
    CGFloat leftMargin = 8;
    CGFloat rightMargin = 8;
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(leftMargin);
        make.centerY.equalTo(self);
        make.top.bottom.equalTo(self);
        make.height.equalTo(@50);
    }];
    
    [self.textfield mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).offset(-rightMargin);
        make.centerY.equalTo(self);
        make.height.equalTo(@40);
        make.left.equalTo(self.titleLabel.mas_right).offset(5);
    }];
    [self.btmLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(leftMargin);
        make.right.equalTo(self).offset(-rightMargin);
        make.bottom.equalTo(self);
        make.height.equalTo(@.5);
    }];
}

#pragma mark - textfield 回调

- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [self.textfield endEditing:YES];
    return YES;
}

- (void)setupTitle:(NSString *)title placeHolder:(NSString *)placeHolder keyboardType:(UIKeyboardType)type isSecur:(BOOL)secur{
    self.titleLabel.text = title;
    self.textfield.placeholder = placeHolder;
    self.textfield.keyboardType = type;
    self.textfield.returnKeyType = UIReturnKeyDone;
    if (secur) {
        self.textfield.secureTextEntry = YES;
    }
}
@end

//////////////////////////////////////////
//////////////////////////////////////////

@implementation DYBaseFormView

@end


